import request from '../axios'

/**
 * 评分
 * @param todoId
 * @param scores
 */
export function score (todoId, scoreMap) {
  const names = Object.keys(scoreMap).map(score => score)
  const points = Object.values(scoreMap).map(score => score.point || 0)
  const remarks = Object.values(scoreMap).map(score => score.remark || '')
  const url = '/api/score/'
  const data = {
    names,
    points,
    remarks,
    todoId,
    Loading: true
  }
  return request.post(url, data)
}

/**
 * 获取评分
 * @param todoId
 */
export function list (todoId) {
  const url = `/api/score/${todoId}`
  return request.get(url)
}
